<template>
  <div class="page-login" flex="dir:top cross:stretch">
    <!-- 背景动画 -->
    <ul class="circles">
      <li v-for="n in 10" :key="n"></li>
    </ul>
    <!-- 登录框 -->
    <div class="page-login--layer">
      <div class="page-login--form">
        <p class="page-login--form-title">系统登录</p>
        <p class="page-login--form-subtitle">综合营销管理平台</p>
        <!-- 登录表单 -->
        <ui-form ref="form" label-position="top" :rules="rules" :model="form" size="default">
          <ui-form-item prop="loginId">
            <ui-input type="text" class="login-input" v-model="form.loginId" placeholder="请输入登录ID">
              <i slot="prepend" class="ui-icon-user login-icon"></i>
            </ui-input>
          </ui-form-item>
          <ui-form-item prop="password">
            <ui-input type="password" class="login-input" v-model="form.password" placeholder="请输入密码">
              <i slot="prepend" class="ui-icon-lock login-icon"></i>
            </ui-input>
          </ui-form-item>
        </ui-form>
        <ui-button size="large" @click="loginSubmit" type="primary" class="button-login">登录</ui-button>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex';
export default {
  name: 'login',
  data() {
    return {
      // 登录表单
      form: {
        loginId: '',
        password: '',
      },
      // 校验
      rules: {
        loginId: [{ required: true, message: '请输入登录ID', trigger: 'blur' }],
        password: [{ required: true, message: '请输入登录密码', trigger: 'blur' }],
      },
    };
  },
  methods: {
    // 从vuex中引入登录的函数
    ...mapActions('vxadmin/account', ['login']),
    /**
     * 登录
     */
    loginSubmit() {
      this.$refs['form'].validate(async (valid) => {
        // 表单校验通过
        if (valid) {
          this.login(this.form).then((res) => {
            // console.log(res);
            this.$router.push('/');
          });
        } else {
          this.$nextTick(() => {
            document
              .querySelectorAll('.is-error')[0]
              .querySelector('input')
              .focus();
          });
        }
      });
    },
  },
};
</script>

<style lang="scss">
.page-login {
  width: 100%;
  height: 100vh;
  background-image: url('../assets/image/login/background.png');
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  // 登陆页面控件的容器
  &--layer {
    position: relative;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 1040px;
    height: 540px;
    background-image: url(../assets/image/login/box_background.png);
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    // 银行logo
    .page-login--logo {
      width: 176px;
      height: 38px;
      position: absolute;
      top: 83px;
      left: 83px;
    }

    // 登录表单
    .page-login--form {
      width: 340px;
      position: absolute;
      top: 80px;
      right: 90px;

      &-title {
        font-family: MicrosoftYaHei;
        font-size: 28px;
        color: $color-text-main;
        letter-spacing: 0;
        line-height: 40px;
        margin: 0;
      }

      &-subtitle {
        font-family: MicrosoftYaHei;
        font-size: 20px;
        color: #151515;
        letter-spacing: 0;
        line-height: 40px;
        margin: 0;
        margin-bottom: 25px;
      }

      //验证码
      .hidden-sm-and-up {
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 80px;
        background-color: #cccccc;

        .login-code {
          height: 35px;
          width: 80px;
          display: block;
          border-top-right-radius: 2px;
          border-bottom-right-radius: 2px;
        }
      }

      // 登录按钮
      .button-login {
        margin-top: 8px;
        width: 100%;
      }

      // 输入框左边的图表区域缩窄
      .ui-input-group__prepend {
        padding: 0px 15px;
        background-color: #fff;
        border-right: none;
        position: relative;

        &::after {
          content: ' ';
          position: absolute;
          width: 1px;
          height: 20px;
          background: #dddddd;
          right: 0;
          top: 50%;
          transform: translateY(-50%);
        }

        .login-icon {
          font-size: 20px;
          color: $color-text-sub;
        }

        .login-icon-svg {
          width: 20px;
          height: 20px;
        }
      }

      .ui-input__inner {
        border-left: none;
        border-color: #dddddd;
      }

      .login-input {
        width: 340px;
      }

      .login-code-input {
        width: 250px;
      }

      // 登陆选项
      .page-login--options {
        margin: 0px;
        padding: 0px;
        font-size: 14px;
        color: $color-primary;
        margin-bottom: 15px;
        font-weight: bold;
      }
    }
  }
  .circles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    margin: 0px;
    padding: 0px;
    li {
      position: absolute;
      display: block;
      list-style: none;
      width: 20px;
      height: 20px;
      background: #fff;
      animation: animate 25s linear infinite;
      bottom: -200px;
      @keyframes animate {
        0% {
          transform: translateY(0) rotate(0deg);
          opacity: 1;
          border-radius: 0;
        }
        100% {
          transform: translateY(-1000px) rotate(720deg);
          opacity: 0;
          border-radius: 50%;
        }
      }
      &:nth-child(1) {
        left: 15%;
        width: 80px;
        height: 80px;
        animation-delay: 0s;
      }
      &:nth-child(2) {
        left: 5%;
        width: 20px;
        height: 20px;
        animation-delay: 2s;
        animation-duration: 12s;
      }
      &:nth-child(3) {
        left: 70%;
        width: 20px;
        height: 20px;
        animation-delay: 4s;
      }
      &:nth-child(4) {
        left: 40%;
        width: 60px;
        height: 60px;
        animation-delay: 0s;
        animation-duration: 18s;
      }
      &:nth-child(5) {
        left: 65%;
        width: 20px;
        height: 20px;
        animation-delay: 0s;
      }
      &:nth-child(6) {
        left: 75%;
        width: 150px;
        height: 150px;
        animation-delay: 3s;
      }
      &:nth-child(7) {
        left: 35%;
        width: 200px;
        height: 200px;
        animation-delay: 7s;
      }
      &:nth-child(8) {
        left: 50%;
        width: 25px;
        height: 25px;
        animation-delay: 15s;
        animation-duration: 45s;
      }
      &:nth-child(9) {
        left: 20%;
        width: 15px;
        height: 15px;
        animation-delay: 2s;
        animation-duration: 35s;
      }
      &:nth-child(10) {
        left: 85%;
        width: 150px;
        height: 150px;
        animation-delay: 0s;
        animation-duration: 11s;
      }
    }
  }
}
</style>
